package top.hidoctor.auscultation.feature.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import top.hidoctor.auscultation.R;
import top.hidoctor.auscultation.adapter.YanebenAdapter;
import top.hidoctor.auscultation.adapter.YanebenBzAdapter;
import top.hidoctor.auscultation.base.BaseFragment;
import top.hidoctor.auscultation.bean.AuditBean;
import top.hidoctor.auscultation.bean.LableBean;
import top.hidoctor.auscultation.widget.Player;

public class YangbenFragment extends BaseFragment {

    private RecyclerView rcYangben;
    private List<LableBean.SampleBean> list = new ArrayList<>();
    private YanebenBzAdapter adapter;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_yangben, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        LableBean bean = (LableBean) getArguments().getSerializable("info");
        list.addAll(bean.getSample());
        initView();
    }

    private void initView() {
        rcYangben = getActivity().findViewById(R.id.rc_yangben);
        rcYangben.setLayoutManager(new LinearLayoutManager(getContext()));
        rcYangben.setAdapter(adapter = new YanebenBzAdapter(R.layout.item_yangben_bz, list));
        View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_empty_list, (ViewGroup) rcYangben.getParent(), false);
        adapter.setEmptyView(view);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Player currentPlayer = adapter.getCurrentPlayer();
        if (currentPlayer != null) {
            currentPlayer.stop();
        }
    }
}
